#include <iostream>

using namespace std;

int main()
{
    int a[100];
    int e,s,p,n,i,j,k,b;
    std::cout<<"n=";
    std::cin>>n;
    for (i=0;i<n;i++)
    {
        std::cout<<"a["<<i<<"]=";
        std::cin>>a[i];
    }
    s=0;
    p=1;
    for (i=0;i<n;i++)
    {
        if (i%2==0) p=p*a[i];
        else s=s+a[i];
    }
    std::cout<<"b=";
    std::cin>>b;
    if (((b==0)||(b==1)||(b==2))&&(n%2==1)) {e=s; }
    if (((b==3)||(b==4)||(b==5))&&(n%2==0)) {e=p;}
    if ((b<0)||(b>5))
    {   s=0;
        p=1;
        for (i=0;i<n;i++)
            {
                s=s+a[i];
                p=p*a[i];
            }
            e=s+p;
    }
    std::cout<<"E="<<e;
    return 0;
}


